package com.magicsoft.app.helper;

import java.io.ByteArrayOutputStream;
import java.io.UnsupportedEncodingException;
import java.lang.reflect.Type;
import java.util.ArrayList;
import java.util.List;
import android.content.Context;
import android.content.SharedPreferences;
import android.content.SharedPreferences.Editor;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;

import com.example.app.AppJson;
import com.example.contactfragment.GroupMember;
import com.example.contactfragment.MyGroup;
import com.example.newfragment.DetailPerson;
import com.example.weather.Allcity;
import com.example.weather.Hotcity;
import com.google.gson.Gson;
import com.google.gson.reflect.TypeToken;
import com.magicsoft.app.entity.AllNewBulletin;
import com.magicsoft.app.entity.CaseDetailEntity;
import com.magicsoft.app.entity.CommunityResp;
import com.magicsoft.app.entity.EmployeeRightsEntity;
import com.magicsoft.app.entity.RememberEntity;
import com.magicsoft.app.entity.WeatherResp;
import com.magicsoft.weitown.fragment.HomeList;
import com.ttcaca.cas.android.client.model.User;

/**
 * 
 * @author ender
 * @category 用于保存在手机临时数据
 * 
 */
public class SharePreferenceHelper {

	public final static String SHAREPREFENCENAME = "WeiTown";
	// 缓存热门城市列表
	public final static String Holder_HotCityList = "holder_hotcitylist";
	// 缓存全部城市列表
	public final static String Holder_AllCityList = "holder_allcitylist";
	// 缓存群组列表
	public final static String GroupsList = "GroupsList";
	//缓存case群组列表
	public final static String CaseGroupsList = "CaseGroupsList";
	// 缓存应用列表
	public final static String Cache_AppList = "Cache_AppList";
	
	// 保存JPush信息条数
	public final static String Jpush_num = "JPUSH_NUM";
	
	// 缓存首页列表
		public final static String Holder_NewEmployeeRights_Entity = "Holder_NewEmployeeRights_Entity";

	// APP版本，用于检测新版本
	public final static String LOCALVERSIONNUM = "LocalVersionNum";
	public final static String SERVERVERSIONNUM = "ServerVersionNum";
	public final static String CLIENTURLPATH = "ClientUrlPath";
	// 保存当前城市
	public final static String SaveCurrentCity = "CURRENTCITY";
	// 账号
	public final static String WeiTown_Account = "WeiTown_Account";
	// 搜索记录
	public final static String WeiTown_CONTACT_SEARCH_HISTORY_DATAS = "WeiTown_CONTACT_SEARCH_HISTORY_DATAS";
	// 记住我
	public final static String WEITOWN_REMEMBER_ENTITY = "WeiTown_Remember_Entity";
	// TOKEN
	public final static String Login_TOKEN = "WeiTown_Token";
	// mDeviceID 注册设备号
	public final static String mDeviceID = "mDeviceID";
	// 启动界面
	public final static String INTRO = "Wei_Town";
	// 缓存首页会员卡
	public final static String WeiTown_home_card_list = "WEITOWN_HOME_CARD_LIST";

	// 缓存天气更新时间
	public final static String WeiTown_weather_time = "WEITOWN_WEATHER_TIME";

	// 缓存天气实体
	public final static String WeiTown_weather_entity = "WEITOWN_WEATHER_ENTITY";
	// 缓存所有公告
	public final static String WeiTown_Bulltin_entity = "WEITOWN_BULLTIN_ENTITY";

	// 缓存小区列表信息实体
	public final static String WeiTown_community_entitys = "WEITOWN_COMMUNITY_ENTITYS";
	// 缓存小区选中信息实体
	public final static String WeiTown_community_entity = "WEITOWN_COMMUNITY_ENTITY";
	// 缓存首页列表实体
	public final static String Holder_EmployeeRights_Entity = "Holder_EmployeeRights_Entity";

	// 缓存消息中心列表
	public final static String WeiTown_Msg_entity = "WEITOWN_MSG_ENTITY";
	public final static String WeiTown_STRING_entity = "WeiTown_STRING_entity";
	// 缓存推荐卡实体
	public final static String WeiTown_RecommendCard_entity = "WeiTown_RecommendCard_entity";
	// 缓存推荐卡获取时间
	public final static String WeiTown_RecommendCard_time = "WEITOWN_RECOMMENDCARD_TIME";

	public final static String SURRUNTDING_HISTORY_KEY = "SURRUNTDING_HISTORY_KEY";
	// 保存JPush的Registration
	public final static String Registration = "REGISTRATION";
	// 保存当前城市天气的pm
	public final static String SaveCurrentCityPm = "SAVECURRENTCITYPM";

	// 保存个人头像Uri
	public final static String SavePersonHeadIcon = "SavePersonHeadIcon";
	// 保存个人信息
	public final static String SavePersonInfo = "SavePersonInfo";
	// 缓存常用联系人列表
	private static final String ContactFrindList = "ContactFrindList";
	private static final String XingbiaoFrindList = "XingbiaoFrindList";
	private static final String MyFrindList = "MyFrindList";
	private static final String MyFrindPickList = "MyFrindPickList";
	private static final String GroupsDetail = "GroupsDetail";
	private static final String ChatGroupsDetail = "ChatGroupsDetail";
	private static final String HomeList = "HomeList";
	private static final String UncloseCaseList = "unclosecaselist";
	private static final String CloseCaseList = "closecaselist";
	private static final String personPhoto = "personphoto";

	/**
	 * 公共操作方法
	 * 
	 * @param context
	 * @param key
	 * @param value
	 * @return
	 */
	public static Boolean setStringValue(Context context, String key,
			String value) {
		SharedPreferences sharedPreferences = context.getSharedPreferences(
				SHAREPREFENCENAME, 0);
		Editor editor = sharedPreferences.edit();
		editor.putString(key, value);
		return editor.commit();
	}

	public static String getStringValue(Context context, String key) {
		SharedPreferences sharedPreferences = context.getSharedPreferences(
				SHAREPREFENCENAME, 0);
		return sharedPreferences.getString(key, "");
	}

	public static Boolean setIntValue(Context context, String key, int value) {
		SharedPreferences sharedPreferences = context.getSharedPreferences(
				SHAREPREFENCENAME, 0);
		Editor editor = sharedPreferences.edit();
		editor.putInt(key, value);
		return editor.commit();
	}

	public static int getIntValue(Context context, String key) {
		SharedPreferences sharedPreferences = context.getSharedPreferences(
				SHAREPREFENCENAME, 0);
		return sharedPreferences.getInt(key, 0);
	}

	public static Boolean setLongValue(Context context, String key, Long value) {
		SharedPreferences sharedPreferences = context.getSharedPreferences(
				SHAREPREFENCENAME, 0);
		Editor editor = sharedPreferences.edit();
		editor.putLong(key, value);
		return editor.commit();
	}

	public static Long getLongValue(Context context, String key) {
		SharedPreferences sharedPreferences = context.getSharedPreferences(
				SHAREPREFENCENAME, -1);
		return sharedPreferences.getLong(key, -1);
	}

	/**
	 * 泛型通用缓存
	 * */
	public static <T> boolean saveCacheData(Context context, String key,
			List<T> nList) {

		if (nList != null) {

			Gson gson = new Gson();

			SharePreferenceHelper.setStringValue(context, key,
					gson.toJson(nList));

			return true;
		}

		return false;

	}

	/*
	 * 判断是否显示应用
	 */
	public static void setIsShowValue(Context context, String key,
			Boolean isshow) {

		if (context == null) {
			return;
		}

		SharedPreferences sp = context.getSharedPreferences(key, 0);
		Editor edit = sp.edit();
		edit.putBoolean("isshow", isshow);
		edit.commit();
	}

	public static Boolean getIsshowValue(Context context, String key) {

		if (context == null) {
			return true;
		}

		SharedPreferences sp = context.getSharedPreferences(key, 0);
		boolean isshow = sp.getBoolean("isshow", true);
		return isshow;
	}

	/**
	 * 判断登录
	 * 
	 * @param context
	 * @return
	 */
	public static Boolean IsLogin(Context context) {

		String cookie = SharePreferenceHelper.getStringValue(context, "COOKIE");
		if (StringUtils.isEmpty(cookie)) {
			return false;
		} else {
			return true;
		}

	}

	/**
	 * 保存账号
	 * 
	 * @param context
	 * @param entity
	 * @return 是否保存成功
	 */
	public static boolean saveAccount(Context context, User entity) {

		Gson gson = new Gson();

		if (entity == null) {
			SharePreferenceHelper.setStringValue(context, WeiTown_Account, "");
		} else {
			SharePreferenceHelper.setStringValue(context, WeiTown_Account,
					gson.toJson(entity));
		}

		return true;

	}

	/**
	 * 获取管理员
	 * 
	 * @param context
	 * @return 管理员实体
	 */
	public static User GetAccount(Context context) {

		String valueString = SharePreferenceHelper.getStringValue(context,
				WeiTown_Account);

		if (valueString == "") {
			return null;
		}

		Type type = new TypeToken<User>() {
		}.getType();

		Gson gson = new Gson();

		User entity = gson.fromJson(valueString, type);

		return entity;

	}

	/**
	 * 保存记住我实体
	 * 
	 * @param context
	 * @param entity
	 * @return 是否保存成功
	 */
	public static boolean saveRememberEntiy(Context context,
			RememberEntity entity) {

		Gson gson = new Gson();

		if (entity == null) {
			SharePreferenceHelper.setStringValue(context,
					WEITOWN_REMEMBER_ENTITY, "");
		} else {
			SharePreferenceHelper.setStringValue(context,
					WEITOWN_REMEMBER_ENTITY, gson.toJson(entity));
		}

		return true;

	}

	/**
	 * 获取记住我实体
	 * 
	 * @param context
	 * @return 记住实体
	 */
	public static RememberEntity GetRememberEntity(Context context) {

		String valueString = SharePreferenceHelper.getStringValue(context,
				WEITOWN_REMEMBER_ENTITY);

		if (valueString == "") {
			return null;
		}

		Type type = new TypeToken<RememberEntity>() {
		}.getType();

		Gson gson = new Gson();

		RememberEntity entity = gson.fromJson(valueString, type);

		return entity;

	}

	public static void updateToken(String aToken, Context context) {

		if (aToken == null) {
			SharePreferenceHelper.setStringValue(context, Login_TOKEN, "");
		} else {
			SharePreferenceHelper.setStringValue(context, Login_TOKEN, aToken);
		}

	}

	/**
	 * TOKEN
	 * */

	public static String getToken(Context context) {

		String token = SharePreferenceHelper.getStringValue(context,
				Login_TOKEN);

		if (token == null) {
			return "";
		}

		return token;
		// return "5#cbcd09d3ce6397aba161807123cfcced";

	}

	/**
	 * 保存首页天气
	 * 
	 * @param context
	 * @param entity
	 * @return 是否保存成功
	 */
	public static boolean saveWeatherResp(Context context, WeatherResp entity,
			String key) {

		Gson gson = new Gson();

		if (entity == null) {
			SharePreferenceHelper.setStringValue(context,
					WeiTown_weather_entity + key, "");
		} else {
			SharePreferenceHelper.setStringValue(context,
					WeiTown_weather_entity + key, gson.toJson(entity));
		}

		return true;

	}

	/**
	 * 获取首页天气信息
	 * 
	 * @param context
	 * @return 记住实体
	 */
	public static WeatherResp GetWeatherResp(Context context, String key) {

		String valueString = SharePreferenceHelper.getStringValue(context,
				WeiTown_weather_entity + key);

		if (StringUtils.isEmpty(valueString)) {
			return null;
		}

		Type type = new TypeToken<WeatherResp>() {
		}.getType();

		Gson gson = new Gson();

		WeatherResp entity = gson.fromJson(valueString, type);

		return entity;

	}

	/**
	 * 保存首页所有公告
	 * 
	 * @param context
	 * @param entity
	 * @return 是否保存成功
	 */
	public static boolean saveAllBulltin(Context context,
			List<AllNewBulletin> entity, String key) {

		Gson gson = new Gson();

		if (entity == null) {
			SharePreferenceHelper.setStringValue(context,
					WeiTown_Bulltin_entity + key, "");
		} else {
			SharePreferenceHelper.setStringValue(context,
					WeiTown_Bulltin_entity + key, gson.toJson(entity));
		}

		return true;

	}

	/**
	 * 获取首页所有公告
	 * 
	 * @param context
	 * @return 记住实体
	 */
	public static List<AllNewBulletin> GetAllBulltin(Context context, String key) {

		String valueString = SharePreferenceHelper.getStringValue(context,
				WeiTown_Bulltin_entity + key);

		if (StringUtils.isEmpty(valueString)) {
			return null;
		}

		Type type = new TypeToken<List<AllNewBulletin>>() {
		}.getType();

		Gson gson = new Gson();

		List<AllNewBulletin> entity = gson.fromJson(valueString, type);

		return entity;

	}

	/**
	 * 保存首页小区
	 * 
	 * @param context
	 * @param entity
	 * @return 是否保存成功
	 */
	public static boolean saveCommunityList(Context context,
			List<CommunityResp> entity, String key) {

		Gson gson = new Gson();

		if (entity == null) {
			SharePreferenceHelper.setStringValue(context,
					WeiTown_community_entitys + key, "");
		} else {
			SharePreferenceHelper.setStringValue(context,
					WeiTown_community_entitys + key, gson.toJson(entity));
		}

		return true;

	}

	/**
	 * 获取首页小区
	 * 
	 * @param context
	 * @return 记住实体
	 */
	public static List<CommunityResp> getCommunityList(Context context,
			String key) {

		String valueString = SharePreferenceHelper.getStringValue(context,
				WeiTown_community_entitys + key);

		if (StringUtils.isEmpty(valueString)) {
			return null;
		}

		Type type = new TypeToken<List<CommunityResp>>() {
		}.getType();

		Gson gson = new Gson();

		List<CommunityResp> entity = gson.fromJson(valueString, type);

		return entity;

	}

	/**
	 * 保存首页选中小区
	 * 
	 * @param context
	 * @param entity
	 * @return 是否保存成功
	 */
	public static boolean saveCommunityResp(Context context,
			CommunityResp entity, String key) {

		Gson gson = new Gson();

		if (entity == null) {
			SharePreferenceHelper.setStringValue(context,
					WeiTown_community_entity + key, "");
		} else {
			SharePreferenceHelper.setStringValue(context,
					WeiTown_community_entity + key, gson.toJson(entity));
		}

		return true;

	}

	/**
	 * 获取首页选中小区
	 * 
	 * @param context
	 * @return 记住实体
	 */
	public static CommunityResp getCommunityResp(Context context, String key) {

		String valueString = SharePreferenceHelper.getStringValue(context,
				WeiTown_community_entity + key);

		if (StringUtils.isEmpty(valueString)) {
			return null;
		}

		Type type = new TypeToken<CommunityResp>() {
		}.getType();

		Gson gson = new Gson();

		CommunityResp entity = gson.fromJson(valueString, type);

		return entity;

	}

	/**
	 * 保存首页选中小区
	 * 
	 * @param context
	 * @param data
	 * @return 是否保存成功
	 */
	public static boolean saveEmployeeRightsEntity(Context context,
			List<AppJson> data, String key) {

		Gson gson = new Gson();

		if (data == null) {
			SharePreferenceHelper.setStringValue(context,
					Holder_EmployeeRights_Entity + key, "");
		} else {
			SharePreferenceHelper.setStringValue(context,
					Holder_EmployeeRights_Entity + key, gson.toJson(data));
		}

		return true;

	}

	/**
	 * 获取首页选中小区
	 * 
	 * @param context
	 * @return 记住实体
	 */
	public static List<EmployeeRightsEntity> getEmployeeRightsEntity(Context context,
			String key) {

		String valueString = SharePreferenceHelper.getStringValue(context,
				Holder_EmployeeRights_Entity + key);

		if (StringUtils.isEmpty(valueString)) {
			return null;
		}

		Type type = new TypeToken<List<EmployeeRightsEntity>>() {
		}.getType();

		Gson gson = new Gson();

		List<EmployeeRightsEntity> entity = gson.fromJson(valueString, type);

		return entity;

	}

	/*
	 * 保存JPush的Registration
	 */
	public static void setRegistrationId(String id, Context context) {
		SharedPreferences sharedPreferences = context.getSharedPreferences(
				Registration, 0);
		Editor editor = sharedPreferences.edit();

		editor.putString("RegistrationId", id);

		editor.commit();
	}

	public static List<String> getContactSearchHistoryList(Context context,
			String key) {

		String valueString = SharePreferenceHelper.getStringValue(context,
				WeiTown_CONTACT_SEARCH_HISTORY_DATAS + key);

		if (StringUtils.isEmpty(valueString)) {
			return null;
		}

		Type type = new TypeToken<List<String>>() {
		}.getType();

		Gson gson = new Gson();

		List<String> entity = gson.fromJson(valueString, type);

		return entity;

	}

	/**
	 * 保存通讯录搜索历史记录
	 * 
	 * @param context
	 * @param entity
	 * @return 是否保存成功
	 */
	public static boolean saveContactSearchHistoryList(Context context,
			List<String> entity, String key) {

		Gson gson = new Gson();

		if (entity == null) {
			SharePreferenceHelper.setStringValue(context,
					WeiTown_CONTACT_SEARCH_HISTORY_DATAS + key, "");
		} else {
			SharePreferenceHelper.setStringValue(context,
					WeiTown_CONTACT_SEARCH_HISTORY_DATAS + key,
					gson.toJson(entity));
		}

		return true;

	}

	public static String getRegistrationId(Context context) {
		SharedPreferences sp = context.getSharedPreferences(Registration, 0);
		String RegistrationId = sp.getString("RegistrationId", "");
		return RegistrationId;
	}

	/*
	 * 获取当前城市
	 */
	public static String getCurrentCity(Context context) {
		SharedPreferences sharedPreferences = context.getSharedPreferences(
				SaveCurrentCity, 0);
		String CurrentCity = sharedPreferences.getString("save"
				+ SaveCurrentCity, "北京");

		return CurrentCity;
	}

	/*
	 * 保存当前城市的pm
	 */
	public static void setWeatherPm(String pm, Context context) {
		SharedPreferences sharedPreferences = context.getSharedPreferences(
				SaveCurrentCityPm, 0);
		Editor editor = sharedPreferences.edit();
		editor.putString("save" + SaveCurrentCityPm, pm);
		editor.commit();
	}

	/*
	 * 获取当前城市的pm
	 */
	public static String getWeatherPm(Context context) {
		SharedPreferences sharedPreferences = context.getSharedPreferences(
				SaveCurrentCityPm, 0);
		String pm = sharedPreferences.getString("save" + SaveCurrentCityPm,
				"加载中...");

		return pm;
	}

	/**
	 * 获取热门城市列表
	 * 
	 * @param context
	 * @return 记住实体
	 */
	public static ArrayList<Hotcity> getHotCityList(Context context) {

		String valueString = SharePreferenceHelper.getStringValue(context,
				Holder_HotCityList);

		if (StringUtils.isEmpty(valueString)) {
			return new ArrayList<Hotcity>();
		}

		Type type = new TypeToken<List<Hotcity>>() {
		}.getType();

		Gson gson = new Gson();

		ArrayList<Hotcity> HotcityList = gson.fromJson(valueString, type);

		return HotcityList;

	}

	/**
	 * 获取全部城市列表
	 * 
	 * @param context
	 * @return 记住实体
	 */
	public static ArrayList<Allcity> getAllCityList(Context context) {

		String valueString = SharePreferenceHelper.getStringValue(context,
				Holder_AllCityList);

		if (StringUtils.isEmpty(valueString)) {
			return new ArrayList<Allcity>();
		}

		Type type = new TypeToken<List<Allcity>>() {
		}.getType();

		Gson gson = new Gson();

		ArrayList<Allcity> AllcityList = gson.fromJson(valueString, type);

		return AllcityList;

	}

	/**
	 * 保存所有城市列表
	 * 
	 * @param context
	 * @param data
	 * @return 是否保存成功
	 */
	public static boolean saveAllcityList(Context context, List<Allcity> data) {

		Gson gson = new Gson();

		if (data == null) {
			SharePreferenceHelper.setStringValue(context, Holder_AllCityList,
					"");
		} else {
			SharePreferenceHelper.setStringValue(context, Holder_AllCityList,
					gson.toJson(data));
		}

		return true;

	}

	/**
	 * 保存应用列表
	 * 
	 * @param context
	 * @param data
	 * @return 是否保存成功
	 */
	public static boolean saveAppList(Context context,
			List<EmployeeRightsEntity> data) {

		Gson gson = new Gson();

		if (data == null) {
			SharePreferenceHelper.setStringValue(context, Cache_AppList, "");
		} else {
			SharePreferenceHelper.setStringValue(context, Cache_AppList,
					gson.toJson(data));
		}
		return true;

	}

	/**
	 * 获取应用列表
	 * 
	 * @param context
	 * @return 记住实体
	 */
	public static ArrayList<EmployeeRightsEntity> getAppList(Context context) {

		String valueString = SharePreferenceHelper.getStringValue(context,
				Cache_AppList);

		if (StringUtils.isEmpty(valueString)) {
			return new ArrayList<EmployeeRightsEntity>();
		}

		Type type = new TypeToken<List<EmployeeRightsEntity>>() {
		}.getType();

		Gson gson = new Gson();

		ArrayList<EmployeeRightsEntity> applist = gson.fromJson(valueString,
				type);

		return applist;

	}

	/**
	 * 保存热门城市列表
	 * 
	 * @param context
	 * @param data
	 * @return 是否保存成功
	 */
	public static boolean saveHotcityList(Context context, List<Hotcity> data) {

		Gson gson = new Gson();

		if (data == null) {
			SharePreferenceHelper.setStringValue(context, Holder_HotCityList,
					"");
		} else {
			SharePreferenceHelper.setStringValue(context, Holder_HotCityList,
					gson.toJson(data));
		}
		return true;

	}

	/**
	 * 保存群组列表
	 * 
	 * @param context
	 * @param data
	 * @return 是否保存成功
	 */
	public static boolean saveGroupsList(Context context, String yonghu,
			List<MyGroup> data) {

		Gson gson = new Gson();

		if (data == null) {
			SharePreferenceHelper.setStringValue(context, yonghu + GroupsList,
					"");
		} else {
			SharePreferenceHelper.setStringValue(context, yonghu + GroupsList,
					gson.toJson(data));
		}

		return true;
	}

	/**
	 * 获取群组列表
	 * 
	 * @param context
	 * @return 记住实体
	 */
	public static ArrayList<MyGroup> getGroupsList(Context context,
			String yonghu) {

		String valueString = SharePreferenceHelper.getStringValue(context,
				yonghu + GroupsList);

		if (StringUtils.isEmpty(valueString)) {
			return new ArrayList<MyGroup>();
		}

		Type type = new TypeToken<List<MyGroup>>() {
		}.getType();

		Gson gson = new Gson();

		ArrayList<MyGroup> myGroups = gson.fromJson(valueString, type);

		return myGroups;

	}
	
	//保存未关闭case群组列表
	public static boolean saveUncloseCaseList(Context context, String yonghu,
			List<CaseDetailEntity> data) {

		Gson gson = new Gson();

		if (data == null) {
			SharePreferenceHelper.setStringValue(context, yonghu + UncloseCaseList,
					"");
		} else {
			SharePreferenceHelper.setStringValue(context, yonghu + UncloseCaseList,
					gson.toJson(data));
		}

		return true;
	}
	
	
	
	//获取未关闭case群组列表
	public static ArrayList<CaseDetailEntity> getUncloseCaseList(Context context,
			String yonghu) {

		String valueString = SharePreferenceHelper.getStringValue(context,
				yonghu + UncloseCaseList);

		if (StringUtils.isEmpty(valueString)) {
			return new ArrayList<CaseDetailEntity>();
		}

		Type type = new TypeToken<List<CaseDetailEntity>>() {
		}.getType();

		Gson gson = new Gson();

		ArrayList<CaseDetailEntity> myGroups = gson.fromJson(valueString, type);

		return myGroups;

	}
	
	//保存已关闭case群组列表
		public static boolean saveCloseCaseList(Context context, String yonghu,
				List<CaseDetailEntity> data) {

			Gson gson = new Gson();

			if (data == null) {
				SharePreferenceHelper.setStringValue(context, yonghu + CloseCaseList,
						"");
			} else {
				SharePreferenceHelper.setStringValue(context, yonghu + CloseCaseList,
						gson.toJson(data));
			}

			return true;
		}
		
		//获取已关闭case群组列表
		public static ArrayList<CaseDetailEntity> getCloseCaseList(Context context,
				String yonghu) {

			String valueString = SharePreferenceHelper.getStringValue(context,
					yonghu + CloseCaseList);

			if (StringUtils.isEmpty(valueString)) {
				return new ArrayList<CaseDetailEntity>();
			}

			Type type = new TypeToken<List<CaseDetailEntity>>() {
			}.getType();

			Gson gson = new Gson();

			ArrayList<CaseDetailEntity> myGroups = gson.fromJson(valueString, type);

			return myGroups;

		}
	
	
	//缓存首页列表
		public static boolean saveHomeList(Context context, String yonghu,
				List<HomeList> data) {

			Gson gson = new Gson();

			if (data == null) {
				SharePreferenceHelper.setStringValue(context, yonghu + HomeList,
						"");
			} else {
				SharePreferenceHelper.setStringValue(context, yonghu + HomeList,
						gson.toJson(data));
			}

			return true;
		}
		
		//获取首页列表缓存
		public static ArrayList<HomeList> getHomeList(Context context,
				String yonghu) {

			String valueString = SharePreferenceHelper.getStringValue(context,
					yonghu + HomeList);

			if (StringUtils.isEmpty(valueString)) {
				return new ArrayList<HomeList>();
			}

			Type type = new TypeToken<List<HomeList>>() {
			}.getType();

			Gson gson = new Gson();

			ArrayList<HomeList> homeList = gson.fromJson(valueString, type);

			return homeList;

		}
		

	// 保存聊天界面的群组成员
	public static boolean saveChatGroupsDetail(Context context, String yonghu,
			String groupid, List<GroupMember> data) {

		Gson gson = new Gson();

		if (data == null) {
			SharePreferenceHelper.setStringValue(context, yonghu + groupid
					+ ChatGroupsDetail, "");
		} else {
			SharePreferenceHelper.setStringValue(context, yonghu + groupid
					+ ChatGroupsDetail, gson.toJson(data));
		}

		return true;
	}

	// 获取聊天界面的群组成员
	public static ArrayList<GroupMember> getChatGroupsDetail(Context context,
			String yonghu, String groupid) {

		String valueString = SharePreferenceHelper.getStringValue(context,
				yonghu + groupid + ChatGroupsDetail);

		if (StringUtils.isEmpty(valueString)) {
			return new ArrayList<GroupMember>();
		}

		Type type = new TypeToken<List<GroupMember>>() {
		}.getType();

		Gson gson = new Gson();

		ArrayList<GroupMember> groupDetail = gson.fromJson(valueString, type);

		return groupDetail;

	}

	// 保存群组详情
	public static boolean saveGroupsDetail(Context context, String yonghu,
			String groupid, List<GroupMember> data) {

		Gson gson = new Gson();

		if (data == null) {
			SharePreferenceHelper.setStringValue(context, yonghu + groupid
					+ GroupsDetail, "");
		} else {
			SharePreferenceHelper.setStringValue(context, yonghu + groupid
					+ GroupsDetail, gson.toJson(data));
		}

		return true;
	}

	// 获取群组详情
	public static ArrayList<GroupMember> getGroupsDetail(Context context,
			String yonghu, String groupid) {

		String valueString = SharePreferenceHelper.getStringValue(context,
				yonghu + groupid + GroupsDetail);

		if (StringUtils.isEmpty(valueString)) {
			return new ArrayList<GroupMember>();
		}

		Type type = new TypeToken<List<GroupMember>>() {
		}.getType();

		Gson gson = new Gson();

		ArrayList<GroupMember> groupDetail = gson.fromJson(valueString, type);

		return groupDetail;

	}

	// 保存常用联系人列表
	public static boolean saveContactFrindList(Context context, String yonghu,
			List<DetailPerson> data) {

		Gson gson = new Gson();

		if (data == null) {
			SharePreferenceHelper.setStringValue(context, yonghu
					+ ContactFrindList, "");
		} else {
			SharePreferenceHelper.setStringValue(context, yonghu
					+ ContactFrindList, gson.toJson(data));
		}

		return true;
	}

	// 获取常用联系人列表
	public static ArrayList<DetailPerson> getContactFrindList(Context context,
			String yonghu) {

		String valueString = SharePreferenceHelper.getStringValue(context,
				yonghu + ContactFrindList);

		if (StringUtils.isEmpty(valueString)) {
			return new ArrayList<DetailPerson>();
		}

		Type type = new TypeToken<List<DetailPerson>>() {
		}.getType();

		Gson gson = new Gson();

		ArrayList<DetailPerson> myContactFrindList = gson.fromJson(valueString,
				type);

		return myContactFrindList;

	}

	// 保存星标联系人列表
	public static boolean saveXingbiaoFrindList(Context context, String yonghu,
			List<DetailPerson> data) {

		Gson gson = new Gson();

		if (data == null) {
			SharePreferenceHelper.setStringValue(context, yonghu
					+ XingbiaoFrindList, "");
		} else {
			SharePreferenceHelper.setStringValue(context, yonghu
					+ XingbiaoFrindList, gson.toJson(data));
		}

		return true;
	}

	// 获取星标联系人列表
	public static ArrayList<DetailPerson> getXingbiaoFrindList(Context context,
			String yonghu) {

		String valueString = SharePreferenceHelper.getStringValue(context,
				yonghu + XingbiaoFrindList);

		if (StringUtils.isEmpty(valueString)) {
			return new ArrayList<DetailPerson>();
		}

		Type type = new TypeToken<List<DetailPerson>>() {
		}.getType();

		Gson gson = new Gson();

		ArrayList<DetailPerson> myXingbiaoFrindList = gson.fromJson(
				valueString, type);

		return myXingbiaoFrindList;

	}

	// 保存我的好友列表
	public static boolean saveMyFrindList(Context context, String yonghu,
			List<DetailPerson> data) {

		Gson gson = new Gson();

		if (data == null) {
			SharePreferenceHelper.setStringValue(context, yonghu + MyFrindList,
					"");
		} else {
			SharePreferenceHelper.setStringValue(context, yonghu + MyFrindList,
					gson.toJson(data));
		}

		return true;
	}

	// 获取我的好友列表
	public static ArrayList<DetailPerson> getMyFrindList(Context context,
			String yonghu) {

		String valueString = SharePreferenceHelper.getStringValue(context,
				yonghu + MyFrindList);

		if (StringUtils.isEmpty(valueString)) {
			return new ArrayList<DetailPerson>();
		}

		Type type = new TypeToken<List<DetailPerson>>() {
		}.getType();

		Gson gson = new Gson();

		ArrayList<DetailPerson> myFrindList = gson.fromJson(valueString, type);

		return myFrindList;

	}
	
	// 保存我的好友列表
		public static boolean saveMyFrindPickList(Context context, String yonghu,
				List<DetailPerson> data) {

			Gson gson = new Gson();

			if (data == null) {
				SharePreferenceHelper.setStringValue(context, yonghu + MyFrindPickList,
						"");
			} else {
				SharePreferenceHelper.setStringValue(context, yonghu + MyFrindPickList,
						gson.toJson(data));
			}

			return true;
		}

		// 获取我的好友列表
		public static ArrayList<DetailPerson> getMyFrindPickList(Context context,
				String yonghu) {

			String valueString = SharePreferenceHelper.getStringValue(context,
					yonghu + MyFrindPickList);

			if (StringUtils.isEmpty(valueString)) {
				return new ArrayList<DetailPerson>();
			}

			Type type = new TypeToken<List<DetailPerson>>() {
			}.getType();

			Gson gson = new Gson();

			ArrayList<DetailPerson> myFrindList = gson.fromJson(valueString, type);

			return myFrindList;

		}

	/*
	 * 保存当前的城市
	 */
	public static void setCurrentCity(String CurrentCity, Context context) {
		SharedPreferences sharedPreferences = context.getSharedPreferences(
				SaveCurrentCity, 0);
		Editor editor = sharedPreferences.edit();
		editor.putString("save" + SaveCurrentCity, CurrentCity);
		editor.commit();
	}

	/*
	 * 保存当前个人头像Uri
	 */
	public static void setHeadIconUri(String headIconUri, Context context) {
		SharedPreferences sharedPreferences = context.getSharedPreferences(
				SavePersonHeadIcon, 0);
		Editor editor = sharedPreferences.edit();

		editor.putString("save" + SavePersonHeadIcon, headIconUri);

		editor.commit();
	}

	/*
	 * 获取当前个人头像Uri
	 */
	public static String getHeadIconUri(Context context) {
		SharedPreferences sharedPreferences = context.getSharedPreferences(
				SavePersonHeadIcon, 0);

		String headIconUri = sharedPreferences.getString("save"
				+ SavePersonHeadIcon, "");

		return headIconUri;
	}
	
	/*
	 * 保存新来消息的条数
	 */
	public static void setUnreadNum(String caseid, Context context, int num){
		SharedPreferences sp = context.getSharedPreferences(Jpush_num, 0);
		Editor edit = sp.edit();
		edit.putInt(caseid, num);
		edit.commit();
	}
	
	public static int getUnreadNum(Context context, String caseid){
		SharedPreferences sp = context.getSharedPreferences(Jpush_num, 0);
		int num = sp.getInt(caseid, 0);
		return num;
	}
	
	/**
	 * 保存首页列表
	 * 
	 * @param context
	 * @param data
	 * @return 是否保存成功
	 */
	public static boolean saveNewEmployeeRightsEntity(Context context,
			List<HomeList> data, String key) {

		Gson gson = new Gson();

		if (data == null) {
			SharePreferenceHelper.setStringValue(context,
					Holder_NewEmployeeRights_Entity + key, "");
		} else {
			SharePreferenceHelper.setStringValue(context,
					Holder_NewEmployeeRights_Entity + key, gson.toJson(data));
		}

		return true;

	}
	
//	//保存个人头像
//	public static void savePersonPhoto(String uid, Context context, Bitmap bitmap){
//		SharedPreferences sp = context.getSharedPreferences(personPhoto, 0);
//		Editor edit = sp.edit();
//		byte[] bitmaptobyte = bitmaptobyte(bitmap);
//		String str;
//		try {
//			str = new String(bitmaptobyte, "UTF-8");
//			edit.putString(uid, str);
//			edit.commit();
//		} catch (UnsupportedEncodingException e) {
//			// TODO Auto-generated catch block
//			e.printStackTrace();
//		}
//	}
//	
//	public static Bitmap getPersonPhoto(Context context, String uid){
//		SharedPreferences sp = context.getSharedPreferences(personPhoto, 0);
//		String str = sp.getString(uid, "");
//		byte[] bytes;
//		Bitmap bitmap = null;
//		try {
//			bytes = str.getBytes("UTF-8");
//			bitmap = BitmapFactory.decodeByteArray(bytes, 0, bytes.length);
//		} catch (UnsupportedEncodingException e) {
//			// TODO Auto-generated catch block
//			e.printStackTrace();
//		}
//		return bitmap;
//	}
	
	public static byte[] bitmaptobyte(Bitmap bitmap){
		ByteArrayOutputStream baos = new ByteArrayOutputStream();
			bitmap.compress(Bitmap.CompressFormat.PNG, 100, baos);
			return baos.toByteArray();
	}
}
